<template>
	<view>
		<view class="list" v-for="item in list" :key='item.id' @click="goto(item)">
			<view class="center flex-1 ml-3 ">
				<view class="name">
					<view class="text-truncate">参赛选手:{{user.nickName}}</view>
					<view class="size">答对题数:{{item.score}}</view>
					<view class="size">竞赛时间:{{item.times}}</view>
				</view>
				<view :class="[item.changes >= 0? 'price-2':'price-1']">
					积分变化:{{item.changes}}
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				list: [],
				user: {}
			};
		},
		async onLoad() {
			await this.getChangeResult()
		},
		methods: {
			goto(item) {
				let list = item.result;
				let score = item.score;
				uni.navigateTo({
					url: `/pages/challenge/challengeResult?score=${score}&list=${list}`
				});
			},
			getChangeResult() {
				this.user = uni.getStorageSync('user');
				let that = this
				let res = uni.request({
					url: that.serverUrl + `/challenge/test`,
					method: "GET",
					header: {
						'Content-type': 'application/x-www-form-urlencoded'
					},
					data: {
						userId: that.user.id
					},
					success: (res) => {

						console.log(res)
						this.list = res.data
						// // list数组中为每一项添加双向绑定的属性---这个属性要在页面显示(onShow)添加
						// this.list.forEach(el => el.isChecked = false);
						// this.tlist = this.list; //真实数据赋值给页面数据
					}
				})
			}
		}
	}
</script>

<style lang="scss">
	.list {
		width: 672rpx;
		height: 208rpx;
		background: #fff;
		box-shadow: 0 8rpx 16rpx 0 rgba(83, 66, 49, 0.08);
		border-radius: 24rpx;
		margin-top: 32rpx;
		display: flex;
		justify-content: space-around;
		align-items: center;

		.left {
			display: flex;

			.img {
				width: 136rpx;
				height: 136rpx;
				margin-left: 10rpx;
				border-radius: 8%;
			}
		}

		.center {
			width: 170rpx;
			display: flex;
			height: 136rpx;
			flex-direction: column;
			justify-content: space-between;

			.name {
				font-size: 26rpx;
				color: #3E3E3E;
				white-space: nowrap;
				text-overflow: ellipsis;
				overflow: hidden;
			}

			.size {
				font-size: 22rpx;
				color: #8D8D8D;
			}

			.price-1 {
				color: #DD6C26;
				font-weight: bold;
			}

			.price-2 {
				color: #aaff7f;
				font-weight: bold;
			}
		}

		.right {
			display: flex;
			height: 136rpx;
			flex-direction: column;
			justify-content: space-between;
			align-items: center;

			.count {
				font-size: 22rpx;
				color: #8D8D8D;
			}

			.types {
				width: 120rpx;
				height: 50rpx;
				color: #FFFFFF;
			}

			.types_dfk {
				background-color: #00aaff;
			}


			.types_ywc {
				background-color: #0BC261;
			}

			.types_yqx {
				background-color: #FF976A;
			}

			.types_aaa {
				background-color: #aaaa00;
			}
		}
	}
</style>